<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<link rel="stylesheet" href="/static/css/metro-all.min.css">
	<link rel="stylesheet" href="/static/css/schemes/darcula.min.css">
</head>
<body class="bg-dack m-0 p-2">
	<!--  -->
	<header class="grid text-left">
		<div class="row mt-10">
			<div class="cell-12">
				<div data-role="appbar" data-expand-point="md">
					<a href="#" class="brand no-hover"> dreamcc</a>
					<ul class="app-bar-menu">
						<li><a href="#">首页</a></li>
						<li>
							<a href="#" class="dropdown-toggle">测试</a>
							<ul class="d-menu" data-role="dropdown">
								<li><a href="#">二级</a></li>
								<li><a href="#">菜单</a></li>
								<li><a href="#">展示</a></li>
							</ul>
						</li>
						<li><a href="#">文章</a></li>
						<li><a href="#">用户</a></li>
					</ul>
				</div>
			</div>
		</div>
		<div class="row mt-10">
			<div class="cell-12">
				<h4>权限列表</h4>
			</div>
		</div>
	</header>

	</header>
	<!--  -->
	<section>
		<article class="grid text-left">
		<div class="row">
			<div class="cell-12">
			<table class="table striped row-hover cell-hover table-border row-border">
			<thead>
				<tr>
					<th class="text-center">名称</th>
					<th class="text-center">路径</th>
					<!-- <th class="text-center">等级</th>
					<th class="text-center">上级</th>
					<th class="text-center">显示</th>
					<th class="text-center">排序</th> -->
					<!-- <th class="text-center">描述</th> -->
					<th class="text-center">操作</th>
				</tr>
			</thead>
			<tbody id="tabledata" >
				
			</tbody>
			<tfoot>
				<tr>
					<th class="text-center"><button class="button">查看权限树</button></th>
					<th class="text-center"></th>
			<!-- 		<th class="text-center"></th>
					<th class="text-center"></th>
					<th class="text-center"></th>
					<th class="text-center"><button class="button">进行排序</button></th> -->
					<!-- <th class="text-center"></th> -->
					<th class="text-center"><button class="button info" onclick="addRulesurl()">添加</button></th>
				</tr>
			</tfoot>
			</table>

			</div>
		</div>
		<div id='page'></div>
		</article>
	</section>
	<!--  -->
	<footer class="grid text-center">
		
	</footer>
</body>
<foot>
	<div class="bottom-nav pos-absolute">
		<button class="button">
			<span class="icon mif-home"></span>
			<span class="label">首页</span>
		</button>

	    <button class="button" onclick="indexrulseurl()">
			<span class="icon mif-power" ></span>
			<span class="label">规则</span>
		</button>
		<button class="button" onclick="listrulseurl()">
			<span class="icon mif-list"></span>
			<span class="label">列表</span>
		</button>
		<button class="button" onclick="addRulesurl()">
			<span class="icon mif-plus"></span>
			<span class="label">添加</span>
		</button>
		<button class="button">
			<span class="icon mif-user"></span>
			<span class="label">我的</span>
		</button>
	</div>
	<script src="/static/js/jquery-3.3.1.min.js"></script>
	<script src="/static/js/metro.min.js"></script>
	<script>

	function listrulseurl()
	{
		Metro.toast.create('请稍后', function(){
			window.location.href = 'http://www.dreamcc.com/admin/admin_rules/list';
		},1000); 
	}
	function addRulesurl()
	{
		Metro.toast.create('请稍后', function(){
			window.location.href = 'http://www.dreamcc.com/admin/admin_rules/add';
		},1000); 
	}
	function indexrulseurl()
	{
		Metro.toast.create('请稍后', function(){
			window.location.href = 'http://www.dreamcc.com/admin/admin_rules/list';
		},1000); 
	}

	function pagelist(page=0)
	{
		var url = 'http://www.dreamcc.com/admin/admin_rules/listRulse.html';
		$.post(url,{page:page},function(res)
		{
			if (0 === res.code)
			{
				data = tableDataProcessing(res.data.data)
				$("#tabledata").html(data);
				$("#page").html('');
				$("#page").html(res.data.page);
			} else {
				$("#tabledata").html('<tr><td class="text-center" colspan="10"><h5>暂时没有数据，请前往添加</h5></td></tr>');
			}
		});
	}
	pagelist();
	function tableDataProcessing(res)
	{
		str = '';
		for (var i = 0; i < res.length; i++)
		{
			str += '<tr>'+
			'<td>'+res[i].title+'</td>'+
			'<td>'+res[i].name+'</td>'+
			'<td><button class="button" onclick="getDetails('+res[i].id+')">查看</button></td>'+
			'</tr>';
		}
		return str;
	}
	
	function getDetails(id)
	{
		var url = 'http://www.dreamcc.com/admin/admin_rules/getRulse.html';
		$.post(url,{id:id},function(res)
		{
			if (0 === res.code)
			{
				Metro.toast.create('请稍后', function(){
					Metro.storage.setItem('rules_detauls', res.data[0]);
					window.location.href = 'http://www.dreamcc.com/admin/admin_rules/edit';
				},1000); 
			}
			else { Metro.toast.create(res.msg, null, 3000);}
		});
	}
	</script>
</foot>
</html>

